
//
//  YQMYBaseViewController.m
//  MuYing
//
//  Created by tbb on 2019/7/18.
//  Copyright © 2019 TBB. All rights reserved.
//

#import "YQMYBaseViewController.h"

@interface YQMYBaseViewController ()

@end

@implementation YQMYBaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.isNavShadow = NO;
    self.view.backgroundColor = UIColor.whiteColor;
    //如果为第一个页面就不用创建
    if (![self isEqual:self.navigationController.childViewControllers.firstObject]) {
        self.leftItemImage = YQIMG(@"nav_back_sIcon");
    }
    [self _setupNav];
    [self setupView];
}
#pragma -mark 私有
-(void)_setupNav {
    UIFont *font = kSystemMedium(17);
    NSDictionary *dic = @{ NSFontAttributeName:font,NSForegroundColorAttributeName:kAPPMainTitleColor};
    self.navigationController.navigationBar.titleTextAttributes =dic;
    // 一行代码搞定导航栏颜色
    [self wr_setNavBarBarTintColor:[UIColor whiteColor]];
    // 一行代码搞定导航栏底部分割线是否隐藏
    [self wr_setNavBarShadowImageHidden:YES];
}
-(void)setupView {
    
}

-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    if (self.isNavShadow) {
        [self _setNavShadow];
    }
    
}
-(void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    if(self.isNavShadow) {
        [self _clearNavShadow];
    }
    
}

-(void)setLeftItemImage:(UIImage *)leftItemImage {
    _leftItemImage = leftItemImage;
    [self setupNavLeftItem];
}

-(void)setLeftItemTitle:(NSString *)leftItemTitle {
    _leftItemTitle = [leftItemTitle copy];
    
    UIButton *leftBtn = [UIButton buttonWithType:0];
    _leftItem = leftBtn;
    leftBtn.titleLabel.font = kSystemMedium(15);//[UIFont systemFontOfSize:15];
    [leftBtn setTitle:leftItemTitle forState:(UIControlStateNormal)];
    [leftBtn setTitleColor:kAPPMainTitleColor forState:(UIControlStateNormal)];
    [leftBtn addTarget:self action:@selector(leftItemAction:) forControlEvents:(UIControlEventTouchUpInside)];
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithCustomView:leftBtn];
    self.navigationItem.leftBarButtonItem = rightItem;
}

-(void)setRightItemImage:(UIImage *)rightItemImage {
    _rightItemImage = rightItemImage;
    
    UIButton *cloreBtn = [UIButton buttonWithType:0];
    _rightItem = cloreBtn;
    
    [cloreBtn setImage:rightItemImage  forState:(UIControlStateNormal)];
    [cloreBtn addTarget:self action:@selector(rightItemAction:) forControlEvents:(UIControlEventTouchUpInside)];
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithCustomView:cloreBtn];
    self.navigationItem.rightBarButtonItem = rightItem;
}

-(void)setRightItemTitle:(NSString *)rightItemTitle {
    _rightItemTitle = [rightItemTitle copy];
    
    UIButton *cloreBtn = [UIButton buttonWithType:0];
    _rightItem = cloreBtn;
    cloreBtn.titleLabel.font = kSystemMedium(15);//[UIFont systemFontOfSize:15];
    [cloreBtn setTitle:rightItemTitle forState:(UIControlStateNormal)];
    [cloreBtn setTitleColor:kAPPMainTitleColor forState:(UIControlStateNormal)];
    [cloreBtn addTarget:self action:@selector(rightItemAction:) forControlEvents:(UIControlEventTouchUpInside)];
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithCustomView:cloreBtn];
    self.navigationItem.rightBarButtonItem = rightItem;
}

-(void)leftItemAction:(UIButton *)sneder {
    [self backNavItemTapped];
}

-(void)rightItemAction:(UIButton *)sender {
    
}

-(void)setupNavLeftItem {
    UIButton *back = [UIButton buttonWithType:UIButtonTypeCustom];
    [back setFrame:CGRectMake(0, 0, 20.0, 20.0)];//
    
    [back setImage:self.leftItemImage forState:UIControlStateNormal];
    
    //    [back setImageEdgeInsets:UIEdgeInsetsMake(0, -15, 0, 0)];
    [back addTarget:self action:@selector(leftItemAction:) forControlEvents:UIControlEventTouchUpInside];
    back.backgroundColor = [UIColor clearColor];
    _leftItem = back;
    UIBarButtonItem *backButtonItem = [[UIBarButtonItem alloc] initWithCustomView:back];
    self.navigationItem.leftBarButtonItem = backButtonItem;
}

- (void)backNavItemTapped {
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)setupRefresh:(UIScrollView *)scrollView{
    
    scrollView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(onStartRefresh)];
    
    scrollView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(onStartLoadMore)];
    [scrollView.mj_footer endRefreshingWithNoMoreData];
    
}
-(void)onStartRefresh {
    
}
-(void)onStartLoadMore {
    
}
-(NSMutableArray *)dataArr {
    if (!_dataArr) {
        _dataArr = [NSMutableArray array];
    }
    return _dataArr;
}

- (void)removeUIPanGestureRecognizer{
    id traget = self.navigationController.interactivePopGestureRecognizer.delegate;
    UIPanGestureRecognizer * pan = [[UIPanGestureRecognizer alloc]initWithTarget:traget action:nil];
    [self.view addGestureRecognizer:pan];
}
@end
